'use strict';

angular.module('app')
	.controller('backMessageController', [ '$rootScope', '$scope', '$http', '$state',
	                                function($rootScope, $scope, $http, $state) {
		$scope.title = '平台消息管理';
        $scope.param = { };
        $scope.loading = false;
     $scope.messagemobile=true;
		$scope.search = function () {
	        console.log($scope.param);
            $scope.param.source=$("#source").val();
            if($scope.param.messageType==''||$scope.param.messageType==undefined){
                $scope.messageType();
            }
            if($scope.param.pageNum==undefined) {
                if ($scope.param.source == 'lbjr') {
                    $scope.param.messageType = 'A02';
                } else if ($scope.param.source == 'zqh') {
                    $scope.param.messageType = 'B02';
                } else if ($scope.param.source == 'ld') {
                    $scope.param.messageType = 'C02';
                } else if ($scope.param.source == 'lbn') {
                    $scope.param.messageType = 'D01';
                }
            }
            if(($scope.param.messageType=='A01' || $scope.param.messageType=='B01' || $scope.param.messageType=='C01') && ($scope.param.mobile==''||$scope.param.mobile==undefined)){
                $scope.alertModal({'content': '个人消息手机号必填'});
            }else{
                $scope.loading = true;
			$.ajax({
				url : $scope.app.project_name + '/backmessage/read/list',
				data: $scope.param
			}).then(function(result) {
		        $scope.loading = false;
				if (result.httpCode == 200) {
					$scope.pageInfo = result.data;
					console.log(result.data);
				} else {
					$scope.msg = result.msg;
				}
				$scope.$apply();
			});
            }
		}
		$scope.searchRe = function () {
                                            $scope.param.source=$("#source").val();
                                             $scope.param.pageNum=1;

            if(($scope.param.messageType=='A01' || $scope.param.messageType=='B01' || $scope.param.messageType=='C01') && ($scope.param.mobile==''||$scope.param.mobile==undefined)){
                $scope.alertModal({'content': '个人消息手机号必填'});
            }else {
                $scope.loading = true;
                $.ajax({
                    url: $scope.app.project_name + '/backmessage/read/list',
                    data: $scope.param
                }).then(function (result) {
                    $scope.loading = false;
                    if (result.httpCode == 200) {
                        $scope.pageInfo = result.data;
                        console.log(result.data);
                    } else {
                        $scope.msg = result.msg;
                    }
                    $scope.$apply();
                });
            }
                                        }
            $scope.messageType=function(){
                $scope.param.mobile='';
                $scope.messagemobile=true;
                $.ajax({
                    url : $scope.app.project_name + '/hMenu/read/getchannelMenuList',
                    data: $scope.param
                }).then(function(result) {
                    $scope.loading = false;
                    if (result.httpCode == 200) {
                        $scope.channelMenuList= result.data;
                        console.log(result.data);
                        if($scope.param.source=='lbjr'){
                            $scope.param.messageType='A02';
                        }else if($scope.param.source=='zqh'){
                            $scope.param.messageType='B02';
                        }else if($scope.param.source=='ld'){
                            $scope.param.messageType='C02';
                        }else if($scope.param.source=='lbn') {
                            $scope.param.messageType = 'D01';
                        }
                    } else {
                        $scope.msg = result.msg;
                    }
                    $scope.$apply();
                });
            }
            $scope.messagechileType=function(){
                                           if($scope.param.messageType=='A01'||$scope.param.messageType=='B01'||$scope.param.messageType=='C01'){

                                               $scope.messagemobile=false;
                                           }else{
                                               $scope.param.mobile='';
                                               $scope.messagemobile=true;
                                           }
                                        }

        $scope.search();
        $scope.clearSearch = function() {
            $scope.param={};
            $scope.search();
        }
		// 翻页
        $scope.pagination = function (page) {
            $scope.param.pageNum=page;
            $scope.search();
        };
                                        $scope.delSubscribe=function(id,isenable){
                                            $scope.loading = true;
                                            if(isenable=='Y'){
                                                isenable='N';
                                            }else{
                                                isenable='Y';
                                            }
                                            $.ajax({
                                                url : $scope.app.project_name + '/backmessage/delete',
                                                data: {'messageId': id,"isEnable":isenable,"source":$scope.param.source}
                                            }).then(function(result) {
                                                $scope.loading = false;
                                                if (result.httpCode == 200) {
                                                    $scope.param.keyword= null;
                                                    $scope.search();
                                                } else {
                                                    alert("请求失败");
                                                }
                                                $scope.$apply();
                                            });

                                        }
} ]);